package com.techshinogongjian.fp.func;

import com.techshinogongjian.fp.comm.MsgCallback;
import com.techshinogongjian.fp.comm.TwoUsbComm;
import com.fingerUsb.FingerResult;
import com.techshinogongjian.fp.util.FpConst;

public class TwoUsbFuncImpl extends IFingerprintFunc{

	TwoUsbComm mComm;

	public TwoUsbFuncImpl(TwoUsbComm comm) {
		mComm = comm;
	}

	@Override
	public FingerResult tcGetDevFWInfo() {
		return new FingerResult(FpConst.TCY_NSUP);
	}

	@Override
	public int tcDevDetect(int nPort, String sPort) {
		return 0;
	}

	@Override
	public FingerResult tcGetDevSn() {
		if (isBusy()) {
			return new FingerResult(FpConst.TCY_BUSY);
		}

		mComm.setBusy(true);
		FingerResult result = mComm.getSn();
		mComm.setBusy(false);
		return result;
	}

	@Override
	public FingerResult tcGetImage(int nTimeout) {
		return new FingerResult(FpConst.TCY_NSUP);
	}

	@Override
	public int tcIsPressed(int nTimeout) {
		return 0;
	}

	@Override
	public FingerResult tcGetFeature(int nTimeout) {
		return new FingerResult(FpConst.TCY_NSUP);
	}

	@Override
	public FingerResult tcGetTemplate(int nTimeout) {
		return new FingerResult(FpConst.TCY_NSUP);
	}

	@Override
	public FingerResult tcGetResult() {
		return new FingerResult(FpConst.TCY_NSUP);
	}

	@Override
	public int tcCancel() {
		if (mComm.isBusy()) {
			mComm.setCancel();
		}
		return 0;
	}

	@Override
	public boolean isConnected() {
		return false;
	}

	@Override
	public boolean isCancel() {
		return mComm.isCancel();
	}

	@Override
	public boolean isBusy() {
		return mComm.isBusy();
	}

	@Override
	public FingerResult tcSetSecurityLevel(int level) {
		if (isBusy()) {
			return new FingerResult(FpConst.TCY_BUSY);
		}

		mComm.setBusy(true);
		FingerResult result = mComm.setLevel(level);
		mComm.setBusy(false);
		return result;
	}

	@Override
	public FingerResult tcVerify(long fid, MsgCallback callback, int timeout) {
		if (isBusy()) {
			return new FingerResult(FpConst.TCY_BUSY);
		}

		mComm.setBusy(true);
		FingerResult result = mComm.setVerify(fid, timeout, callback);
		mComm.setBusy(false);
		return result;
	}

	@Override
	public FingerResult tcSetTemplate(long fid, byte[] data) {
		if (isBusy()) {
			return new FingerResult(FpConst.TCY_BUSY);
		}

		mComm.setBusy(true);
		FingerResult result = mComm.setTemplate(fid, data);
		mComm.setBusy(false);
		return result;
	}

	@Override
	public FingerResult tcEnroll(final MsgCallback callback, int timeout) {
		if (isBusy()) {
			return new FingerResult(FpConst.TCY_BUSY);
		}

		mComm.setBusy(true);
		FingerResult result = mComm.setEntroll(timeout, callback);
		mComm.setBusy(false);
		return result;
	}
	
	@Override
	public FingerResult tcSetEnrollImageCount(int newCount) {
		if (isBusy()) {
			return new FingerResult(FpConst.TCY_BUSY);
		}

		mComm.setBusy(true);
		FingerResult result = mComm.setEnrollImageCount(newCount);
		mComm.setBusy(false);
		return result;
	}
	
	@Override
	public FingerResult tcBooTL() {
		return new FingerResult(FpConst.TCY_NSUP);
	}
}
